const request  = require('superagent')
const superagent=require('superagent-charset')(request)
const cheerio = require('cheerio')
const getHtml = async (url, delay) => {
    if (delay) {
        await sleep(delay)
    }
    return superagent.get(url)
    .charset('utf-8')
    .timeout({
        response: 10000,
        deadline: 60000
    })
    .retry(10)
    .then((res) => {
        return cheerio.load(res.text)
    })
    .catch( err => {
        console.log(err.message)
        return false
    })
}
function sleep(ms) {
    return new Promise(resolve => setTimeout(resolve, ms));
  }
module.exports = {
    getHtml
}